﻿using System;
using Microsoft.Xrm.Sdk.Client;

namespace CrmConnectionProject
{
    /// <summary>
    /// Stores data regarding a specific connection to Crm server
    /// </summary>
    public class ConnectionDetail : IComparable
    {
        #region Variables

        AuthenticationProviderType _authType;

        /// <summary>
        /// Connection unique identifier
        /// </summary>
        Guid? _connectionId;

        /// <summary>
        /// Name of the connection
        /// </summary>
        string _connectionName;

        /// <summary>
        /// Flag to know if custom authentication
        /// </summary>
        bool _isCustomAuth;

        /// <summary>
        /// Flag to know if we use IFD
        /// </summary>
        bool _useIFD;

        /// <summary>
        /// Flag to know if we use CRM Online
        /// </summary>
        bool _useOnline;

        /// <summary>
        /// Crm Ticket
        /// </summary>
        string _crmTicket;

        /// <summary>
        /// User Domain Name
        /// </summary>
        string _userDomain;

        /// <summary>
        /// User Login
        /// </summary>
        string _userName;

        /// <summary>
        /// User Password
        /// </summary>
        string _userPassword;

        /// <summary>
        /// Use of SSL connection (HTTPS)
        /// </summary>
        bool _useSsl;

        /// <summary>
        /// Server Name
        /// </summary>
        string _serverName;

        /// <summary>
        /// Server Port
        /// </summary>
        string _serverPort;

        /// <summary>
        /// Organization name
        /// </summary>
        string _organization;

        /// <summary>
        /// Organization friendly name
        /// </summary>
        string _organizationFriendlyName;

        /// <summary>
        /// Crm Service Url
        /// </summary>
        string _organizationServiceUrl;

        #endregion

        #region Propriétés

        public AuthenticationProviderType AuthType
        {
            get { return _authType; }
            set { _authType = value; }
        }

        /// <summary>
        /// Gets or sets the connection unique identifier
        /// </summary>
        public Guid? ConnectionId
        {
            get { return _connectionId; }
            set { _connectionId = value; }
        }

        /// <summary>
        /// Gets or sets the name of the connection
        /// </summary>
        public string ConnectionName
        {
            get { return _connectionName; }
            set { _connectionName = value; }
        }

        /// <summary>
        /// Get or set flag to know if custom authentication
        /// </summary>
        public bool IsCustomAuth
        {
            get { return _isCustomAuth; }
            set { _isCustomAuth = value; }
        }

        /// <summary>
        /// Get or set flag to know if we use IFD
        /// </summary>
        public bool UseIFD
        {
            get { return _useIFD; }
            set { _useIFD = value; }
        }

        /// <summary>
        /// Get or set flag to know if we use CRM Online
        /// </summary>
        public bool UseOnline
        {
            get { return _useOnline; }
            set { _useOnline = value; }
        }

        /// <summary>
        /// Get or set the Crm Ticket
        /// </summary>
        [System.Xml.Serialization.XmlIgnore()]
        public string CrmTicket
        {
            get { return _crmTicket; }
            set { _crmTicket = value; }
        }

        /// <summary>
        /// Get or set the user domain name
        /// </summary>
        public string UserDomain
        {
            get { return _userDomain; }
            set { _userDomain = value; }
        }

        /// <summary>
        /// Get or set user login
        /// </summary>
        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        /// <summary>
        /// Get or set the user password
        /// </summary>
        [System.Xml.Serialization.XmlIgnore()]
        public string UserPassword
        {
            get { return _userPassword; }
            set { _userPassword = value; }
        }

        /// <summary>
        /// Get or set the use of SSL connection
        /// </summary>
        public bool UseSsl
        {
            get { return _useSsl; }
            set { _useSsl = value; }
        }

        /// <summary>
        /// Get or set the server name
        /// </summary>
        public string ServerName
        {
            get { return _serverName; }
            set { _serverName = value; }
        }

        /// <summary>
        /// Get or set the server port
        /// </summary>
        public string ServerPort
        {
            get { return _serverPort; }
            set { _serverPort = value; }
        }

        /// <summary>
        /// Get or set the organization name
        /// </summary>
        public string Organization
        {
            get { return _organization; }
            set { _organization = value; }
        }

        /// <summary>
        /// Get or set the organization friendly name
        /// </summary>
        public string OrganizationFriendlyName
        {
            get { return _organizationFriendlyName; }
            set { _organizationFriendlyName = value; }
        }

        /// <summary>
        /// Gets or sets the Crm Service Url
        /// </summary>
        public string OrganizationServiceUrl
        {
            get { return _organizationServiceUrl; }
            set { _organizationServiceUrl = value; }
        }

        #endregion

        #region Méthodes

        /// <summary>
        /// Retourne le nom de la connexion
        /// </summary>
        /// <returns>Nom de la connexion</returns>
        public override string ToString()
        {
            return this.ConnectionName;
        }

        #endregion

        #region IComparable Members

        public int CompareTo(object obj)
        {
            return this.ConnectionName.CompareTo(((ConnectionDetail)obj).ConnectionName);
        }

        #endregion
    }
}
